package com.easylinkin.linkappapi.device.entity;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.easylinkin.linkappapi.common.model.SortModel;
import com.easylinkin.linkappapi.deviceattributestatus.entity.DeviceAttributeStatus;
import com.easylinkin.linkappapi.devicetype.entity.DeviceType;
import com.easylinkin.linkappapi.deviceunit.entity.DeviceUnit;
import com.easylinkin.linkappapi.intelligentrule.entity.IntelligentRuleExpression;
import com.easylinkin.linkappapi.space.entity.LinkappSpace;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

/**
 * <p>
 *
 * </p>
 *
 * @author TongJie
 * @since 2020-04-14
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("linkapp_device")
@ApiModel(description = "设备实体类")
public class Device extends Model<Device> implements Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * id
   */
  @TableId
  @ApiModelProperty(value = "主键ID", required = false, example = "")
  private String id;
  /**
   * 设备编码
   */
  @TableField("code")
  @Length(max = 32, message = "code超长")
  @ApiModelProperty(value = "设备编码", required = false, example = "")
  private String code;

  /**
   * 设备编码-模糊查询条件
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "设备编码-模糊查询", required = false, example = "")
  private String codeLikeQuery;

  /**
   * 设备名称
   */
  @TableField("name")
  @Length(max = 32, message = "name超长")
  @ApiModelProperty(value = "设备名称", required = false, example = "")
  private String name;

  /**
   * 设备状态,0:正常; 1:告警；新增默认：正常
   */
  @TableField("status")
  @ApiModelProperty(value = "设备状态", required = false, example = "0")
  private Integer status;

  /**
   * 是否删除字段 0:已删; 1:存在
   */
  @TableLogic(value = "1", delval = "0")
  @ApiModelProperty(value = "是否删除", required = false, example = "1")
  private Integer deleteState = 1;

  /**
   * 默认1-存在 0- 删除
   */
  @TableField("linkthing_delete")
  @ApiModelProperty(value = "linkThing删除状态", required = false, example = "1")
  private Integer linkthingDelete;

  /**
   * 0:离线; 1:在线 新增默认离线
   */
  @TableField("online_state")
  @ApiModelProperty(value = "在线状态", required = false, example = "1")
  private Integer onlineState;

  /**
   * 电量
   */
  @TableField("battery")
  @ApiModelProperty(value = "电量", required = false, example = "0")
  private Float battery;

  /**
   * 备注
   */
  @TableField("remark")
  @Length(max = 255, message = "remark超长")
  @ApiModelProperty(value = "备注", required = false, example = "")
  private String remark;

  /**
   * 报警开关
   */
  @TableField("alarm_switch")
  @ApiModelProperty(value = "报警开关", required = false, example = "")
  private String alarmSwitch;

  /**
   * 公司编号
   */
  @Length(max = 32, message = "公司id超长")
  @ApiModelProperty(value = "公司编号", required = false, example = "")
  private String companyId;

  /**
   * 项目编号
   */
  @Length(max = 32, message = "项目id超长")
  @ApiModelProperty(value = "项目编号", required = false, example = "")
  private String projectId;

  /**
   * 设备型号
   */
  @Length(max = 32, message = "型号id超长")
  @ApiModelProperty(value = "设备型号ID", required = false, example = "")
  private String deviceUnitId;

  /**
   * 安装时间
   */
  @ApiModelProperty(value = "安装时间", required = false, example = "")
  private Date installTime;

  /**
   * 检修时间（最后一次）
   */
  @ApiModelProperty(value = "检修时间", required = false, example = "")
  private Date repairTime;

  /**
   * 检修时间（下一次）
   */
  @ApiModelProperty(value = "下一次检修时间", required = false, example = "")
  private Date nextRepairTime;

  /**
   * 报文最后推送时间
   */
  @ApiModelProperty(value = "报文最后推送时间", required = false, example = "")
  private Date lastPushTime;

  /**
   * 创建时间
   */
  @ApiModelProperty(value = "创建时间", required = false, example = "")
  private Date createTime;

  /**
   * 创建人
   */
  @Length(max = 32, message = "创建人超长")
  @ApiModelProperty(value = "创建人", required = false, example = "")
  private String creator;

  /**
   * 修改人
   */
  @Length(max = 32, message = "修改人超长")
  @ApiModelProperty(value = "修改人", required = false, example = "")
  private String modifier;

  /**
   * 修改时间
   */
  @ApiModelProperty(value = "修改时间", required = false, example = "")
  private Date modifyTime;

  /**
   * 区域ID
   */
  @Length(max = 32, message = "区域id超长")
  @TableField(strategy = FieldStrategy.IGNORED)
  @ApiModelProperty(value = "区域ID", required = false, example = "")
  private String areaId;

  /**
   * 纬度
   */
  @Length(max = 32, message = "纬度超长")
  @TableField(strategy = FieldStrategy.IGNORED)
  @ApiModelProperty(value = "纬度", required = false, example = "")
  private String latitude;

  /**
   * 经度
   */
  @Length(max = 32, message = "经度超长")
  @TableField(strategy = FieldStrategy.IGNORED)
  @ApiModelProperty(value = "经度", required = false, example = "")
  private String longitude;

  /**
   * 安装位置
   */
  @Length(max = 255, message = "安装位置超长")
  @TableField(value = "site", strategy = FieldStrategy.IGNORED)
  @ApiModelProperty(value = "安装位置", required = false, example = "")
  private String site;

  /**
   * 区域层级路径
   */
  @Length(max = 255, message = "区域路径超长")
  @TableField(strategy = FieldStrategy.IGNORED)
  @ApiModelProperty(value = "区域路径", required = false, example = "")
  private String areaPath;

  /**
   * 租户ID
   */
  @Length(max = 32)
  @ApiModelProperty(value = "租户ID", required = false, example = "")
  private String tenantId;

  /**
   * 室内位置
   */
  @Length(max = 128)
  @TableField(value = "indoor_location", strategy = FieldStrategy.IGNORED)
  @ApiModelProperty(value = "室内位置", required = false, example = "")
  private String indoorLocation;

  /**
   * 工作状态 1:初始化;2：工作； 3:维保
   */
//  @Length(max = 2, message = "工作状态值超长")
  @ApiModelProperty(value = "工作状态", required = false, example = "2")
  private Integer workStatus = 2;

  @TableField("manufacturer")
  @ApiModelProperty(value = "生产厂家", required = false, example = "")
  private String manufacturer;

  @TableField("manufacturer_tel_")
  @ApiModelProperty(value = "联系方式", required = false, example = "")
  private String manufacturerTel;

  @TableField("supplier")
  @ApiModelProperty(value = "供货单位", required = false, example = "")
  private String supplier;

  @TableField("responsible_person")
  @ApiModelProperty(value = "负责人", required = false, example = "")
  private String responsiblePerson;

  @TableField("responsible_person_tel_")
  @ApiModelProperty(value = "联系方式", required = false, example = "")
  private String responsiblePersonTel;

  /**
   * 设备采集频率
   * 默认5000/5秒
   */
  @TableField("collect_freq")
  @ApiModelProperty(value = "设备采集频率 默认5000", required = false, example = "0")
  private Long collectFreq;

  /**
   * 断路器 状态 0合闸 1分闸
   * 默认5000/5秒
   */
  @TableField("elect_status")
  @ApiModelProperty(value = "断路器 状态 0合闸 1分闸", required = false, example = "0")
  private Integer electStatus;


  /**
   * 空间名称（前端显示）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "空间名称", required = false, example = "")
  private String spaceName;


  /**
   * 类型的图标
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "类型的图标", required = false, example = "")
  private String typeIcoPath;

  /**
   * 空间
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "空间实体", required = false, example = "")
  private LinkappSpace linkappSpace;

  /**
   * 区域（前端显示）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "区域", required = false, example = "")
  private String areaName;
  /**
   * 设备类型名称（前端显示）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "设备类型名称", required = false, example = "")
  private String deviceTypeName;

  @TableField(exist = false)
  @ApiModelProperty(value = "设备类型名称集合", required = false, example = "")
  private List<String> deviceTypeNames;

  /**
   * 设备模块id，0为环境模块,-1为安全管理（逻辑概念，没有页面配置）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "设备模块id", required = false, example = "")
  private Integer modelId;

  /**
   * 型号名称（前端显示用）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "型号名称", required = false, example = "")
  private String deviceUnitName;

  /**
   * 型号编号（前端显示用）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "型号编号", required = false, example = "")
  private String deviceUnitCode;

  /**
   * 设备型号版本号（前端显示用）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "设备型号版本号", required = false, example = "")
  private String deviceUnitVersion;

  /**
   * 是否从设备模块已移除 0未移除 1已移除
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "是否从设备模块已移除 0未移除 1已移除", required = false, example = "0")
  private Integer deviceModelRemoveStatus;


  /**
   * 设备类型id(查询条件)
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "设备类型id", required = false, example = "")
  private String deviceTypeId;

  /**
   * 空间id(查询条件)
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "空间id", required = false, example = "")
  private String spaceId;

  /**
   * 创建时间起始（查询条件）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "创建时间起始", required = false, example = "")
  private String queryTimeStart;

  /**
   * 创建时间结束（查询条件）
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "创建时间结束", required = false, example = "")
  private String queryTimeEnd;

  @TableField(exist = false)
  @ApiModelProperty(value = "设备型号实体", required = false, example = "")
  private DeviceUnit deviceUnit;

  @TableField(exist = false)
  @ApiModelProperty(value = "设备类型实体", required = false, example = "")
  private DeviceType deviceType;

  @TableField(exist = false)
  @ApiModelProperty(value = "json", required = false, example = "")
  private String sourceJson;

  /**
   * 设备属性状态 实时
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "设备属性状态", required = false)
  private List<DeviceAttributeStatus> deviceAttributeStatusList;

  /**
   * 所需的设备属性状态参数，需要哪些属性就传哪些
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "所需的设备属性状态参数", required = false)
  private List<String> requiredDeviceAttributeStatusPropCodes;


  @TableField(exist = false)
  @ApiModelProperty(value = "告警规则ID", required = false, example = "")
  private String alarmRuleId;

  @TableField(exist = false)
  @ApiModelProperty(value = "查询条件", required = false, example = "")
  private String moniterCommonQuery;

  @TableField(exist = false)
  @ApiModelProperty(value = "是否绑定告警规则", required = false, example = "")
  private boolean notBindAlarmRule;

  @TableField(exist = false)
  String statisticsTimeType;

  @TableField(exist = false)
  boolean sortAsc;

  //能源分析查询使用
  @TableField(exist = false)
  List<String> deviceUnitCodeList;

  @TableField(exist = false)
  List<String> deviceCodeList;

  @Override
  protected Serializable pkVal() {
    return this.code;
  }

  /**
   * areaId集合
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "区域ID集合", required = false)
  private List<String> areaIds;

  @TableField("filing_no")
  private String filingNo;

  /**
   * 排序标致 配电房环境关联设备用到
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "排序号", required = false, example = "0")
  private Integer sortNo;

  /**
   * 汉川面源车辆管理使用：车牌号
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "汉川面源车辆管理使用：车牌号", required = false, example = "")
  private String carCode;

  /**
   * 查询时-排序参数
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "查询时-排序参数", required = false)
  private List<SortModel> sortModels;

  /***
   * 支持多设备编号查询
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "支持多设备编号查询", required = false)
  private List<String> codes;

  /**
   * 设备多类型id(查询条件)
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "设备多类型id(查询条件)", required = false)
  private List<String> deviceTypeIds;

  /**
   * 属性过滤条件，用于支持设备监控页面的高级过滤功能
   */
  @TableField(exist = false)
  @ApiModelProperty(value = "属性过滤条件，用于支持设备监控页面的高级过滤功能", required = false)
  private List<IntelligentRuleExpression> propertyExpressions;


  @TableField(exist = false)
  @ApiModelProperty(value = "功能标识符，设备分组功能使用", required = false, example = "")
  private String functionIdentifier;

  /**
   * 项目名称
   */
  @TableField(exist = false)
  private String projectName;

  @TableField(exist = false)
  private String projectCode;

  /**
   * 绑定机械名称
   */
  @TableField(exist = false)
  private String bindMachine;

  /**
   * 绑定机械id
   */
  @TableField(exist = false)
  private String bindMachineId;

  /**
   * 绑定机械时间
   */
  @TableField(exist = false)
  private Date bindMachineTime;

  /**
   * 铁路设备类型 DeviceConstant.RailwayDeviceType
   */
  @TableField(exist = false)
  private Integer railDeviceType;

  public boolean equalsLinkthingsDevice(Device item2) {

    return
        this.getDeviceUnitId().equals(item2.getDeviceUnitId())
            && this.getCode().equals(item2.getCode())
            && this.getName().equals(item2.getName())
            && this.getLinkthingDelete().equals(item2.getLinkthingDelete())
            && this.getTenantId().equals(item2.getTenantId())
            && this.getOnlineState().equals(item2.getOnlineState())
        ;
  }

  public Device(Integer linkthingDelete, Integer onlineState, String code, String name,
      String deviceUnitId, String tenantId) {
    this.linkthingDelete = linkthingDelete;
    this.onlineState = onlineState;
    this.code = code;
    this.name = name;
    this.deviceUnitId = deviceUnitId;
    this.tenantId = tenantId;
  }

  public Device() {
  }


  /**
   * 当设备租户信息改变时候 初始化一些属性
   */
  public void initDeviceSomeInfoWhenTenantIdChange() {
    this.setAreaId("");
    this.setLatitude("");
    this.setLongitude("");
    this.setAreaPath("");
    this.setSite("");
    this.setIndoorLocation("");
  }
}
